#include <iostream>
#include <cstring>
using namespace std;

const int N = 100;
char a[N][N];
int n, m, cnt;
bool st[N][N];
bool check(int n, int m)
{
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            if(a[i][j] == '0') continue;
            else
            {
                bool st1 = false, st2 = false;
                for(int k = j - 1; k >= 1; k--)
                {
                    if(a[i][k] != '1') 
                    {
                        st1 = true;
                        break;
                    }
                }
                for(int k = i - 1; k >= 1; k--)
                {
                    if(a[k][j] != '1') 
                    {
                        st2 = true;
                        break;
                    }
                }    
                if((!st1) || (!st2)) cnt--;
                else return false;
            }
        }
    }
    return cnt == 0;
}

int main()
{
    int t; cin >> t;
    while(t--)
    {
        int n, m; cin >> n >> m;
        cnt = 0;
        for(int i = 1; i <= n; i++)
        {
            for(int j = 1; j <= m; j++)
            {
                cin >> a[i][j];
                if(a[i][j] == '1') cnt++;
            }
        }
        // for(int i = 1; i <= n; i++) cout << a[i][1] << endl;
        if(check(n, m)) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}